#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <sys/time.h>

using namespace std;

vector<string> summaryRanges(vector<int>& nums) 
{
  vector<string> ret;
  int begin=0;
  int end=1;
  if(nums.size()==0)
  {
    return ret;
  }


  if(nums.size()>=1)
  {
    for(int i=1;i<=nums.size();++i)
    {
      if( ( nums[i]>(nums[i-1]+1) && i<nums.size() ) || i==nums.size())
      {
        end = i-1;
        stringstream ss;
        ss << nums[begin];
        string s=ss.str();
        if(begin==end)
        {
          ret.push_back(s);
        }
        else
        {
          s+="->";
          stringstream sse;
          sse << nums[end];
          s+=sse.str();
          ret.push_back(s);
        }

        begin = i;
      }


    }

  }


  return ret;

}



int main(int argc,char *argv[])
{

  struct  timeval    tv1,tv2;
  struct  timezone   tz;
  int time1 = gettimeofday(&tv1,&tz);

  vector<int> v1={0,1,2,4,5,7};
  vector<int> v2={0};
  vector<int> v3={-2147483648,-2147483647,2147483647};
  vector<int> v4;
  //func();
  vector<string> ret1;
  ret1 = summaryRanges(v1);
  cout<<"result of v1"<<endl;
  for(auto s : ret1)
  {
    cout<<s<<",";
  }
  cout<<endl;


  vector<string> ret2;
  ret2 = summaryRanges(v2);
  cout<<"result of v2"<<endl;
  for(auto s : ret2)
  {
    cout<<s<<",";
  }
  cout<<endl;


  vector<string> ret3;
  ret3 = summaryRanges(v3);
  cout<<"result of v3"<<endl;
  for(auto s : ret3)
  {
    cout<<s<<",";
  }
  cout<<endl;

  int time2 = gettimeofday(&tv2,&tz);
  cout << "time consuming(local machine/leetcode server):"<<endl
    <<"leetcode server time consuming should be less than 500ms"<<endl
    << tv2.tv_usec - tv1.tv_usec <<"us/"<<0.11*( tv2.tv_usec - tv1.tv_usec )<<"ms"<< endl;



  return 0;
}
